package com.ruoyi.project.system.researchers.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.researchers.domain.Researchers;
import com.ruoyi.project.system.researchers.service.IResearchersService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * researchersController
 * 
 * @author admin
 * @date 2025-04-24
 */
@Controller
@RequestMapping("/cross/researchers")
public class ResearchersController extends BaseController
{
    private String prefix = "cross/researchers";

    @Autowired
    private IResearchersService researchersService;

    @RequiresPermissions("cross:researchers:view")
    @GetMapping()
    public String researchers()
    {
        return prefix + "/researchers";
    }

    /**
     * 查询researchers列表
     */
    @RequiresPermissions("cross:researchers:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Researchers researchers)
    {
        startPage();
        List<Researchers> list = researchersService.selectResearchersList(researchers);
        return getDataTable(list);
    }

    /**
     * 导出researchers列表
     */
    @RequiresPermissions("cross:researchers:export")
    @Log(title = "researchers", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Researchers researchers)
    {
        List<Researchers> list = researchersService.selectResearchersList(researchers);
        ExcelUtil<Researchers> util = new ExcelUtil<Researchers>(Researchers.class);
        return util.exportExcel(list, "researchers数据");
    }

    /**
     * 新增researchers
     */
    @RequiresPermissions("cross:researchers:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存researchers
     */
    @RequiresPermissions("cross:researchers:add")
    @Log(title = "researchers", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Researchers researchers)
    {
        return toAjax(researchersService.insertResearchers(researchers));
    }

    /**
     * 修改researchers
     */
    @RequiresPermissions("cross:researchers:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Researchers researchers = researchersService.selectResearchersById(id);
        mmap.put("researchers", researchers);
        return prefix + "/edit";
    }

    /**
     * 修改保存researchers
     */
    @RequiresPermissions("cross:researchers:edit")
    @Log(title = "researchers", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Researchers researchers)
    {
        return toAjax(researchersService.updateResearchers(researchers));
    }

    /**
     * 删除researchers
     */
    @RequiresPermissions("cross:researchers:remove")
    @Log(title = "researchers", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(researchersService.deleteResearchersByIds(ids));
    }
}
